package edu.hut.mpdemo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import edu.hut.mpdemo.entity.Course;
import edu.hut.mpdemo.entity.Sc;
import edu.hut.mpdemo.entity.Student;
import edu.hut.mpdemo.entity.StudentScCourse;
import edu.hut.mpdemo.mapper.CourseMapper;
import edu.hut.mpdemo.mapper.ScMapper;
import edu.hut.mpdemo.mapper.StudentMapper;
import edu.hut.mpdemo.service.IScService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author xxx
 * @since 2024-04-10
 */
@Service
public class ScServiceImpl extends ServiceImpl<ScMapper, Sc> implements IScService {
    @Resource
    ScMapper scMapper;

    //    要在接口中申明，这里重载，才能在controller中调用
    @Override
    public void testJoin() {
        //scMapper要更改为 实现MPJBaseMapper接口，加入mybatis-plus-join依赖
        List<StudentScCourse> studentScCourseList = scMapper.selectJoinList(StudentScCourse.class,
                new MPJLambdaWrapper<Sc>()
                        .selectAll(Sc.class)
                        .selectAll(Student.class)
                        .selectAll(Course.class)
//                      被链接的表在左边，否则报错
                        .leftJoin(Student.class, Student::getSno, Sc::getSno)
                        .leftJoin(Course.class, Course::getCno, Sc::getCno)
//                      选择单列
//                      .select(Student::getAge)
//                      如果同名
//                      .selectAs(Student::getSno, StudentScCourse::getXXX)
//                      加上where条件
//                      .eq(UserDO::getId, 1)
//                      .like(UserAddressDO::getTel, "1")
//                      .gt(UserDO::getId, 5)
        );
        System.out.println(studentScCourseList);
    }

}
